<%-- 
displays a list of article and their summaries
--%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<t:template>
	<c:choose> 
		<c:when test="${empty articleList}">
			<%-- No articles returned --%>
			<h4>There are no articles under this category</h4>
		</c:when>		
		<c:otherwise>
			<%-- display each article in turn --%>
			<c:set var="count" value="${0}" /> <%-- counter --%>
			<c:forEach var="article" items="${articleList}">
				
				<c:choose>
					<c:when test="${count == 0}">
					<%-- Lead article shown differently --%>
						<section class="lead_article">
							<header>
								<a class="article_link" href="${article.articleURL}">${article.title}</a>
								<br /><time>${article.dateString}</time>
							</header>
							<c:if test="${!empty article.imageLocation}">
								<img class="img_med" src="${article.imageLocation}" />
							</c:if>
							<p>${article.summary}</p>
							<br class="clear" />
						</section>
					</c:when>
					<c:otherwise>
					<%-- otherwise show article normally --%>
						<section class="normal_article">
							<header>
								<a class="article_link" href="${article.articleURL}">${article.title}</a>
								<br /><time>${article.dateString}</time>
							</header>
							<c:if test="${!empty article.imageLocation}">
								<img class="img_small" src="${article.imageLocation}" />
							</c:if>
							<p>${article.summary}</p>
							<br class="clear" />
						</section>
					</c:otherwise>
				</c:choose>
				
				<c:set var="count" value="${count + 1}" /> <%-- increment count --%>
			</c:forEach>
		</c:otherwise>
	</c:choose>	
	<br class="clear" />
</t:template>